package com.tan.springcloud.Service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class HystrixService {
    public String getHystrix(Integer id){
        return Thread.currentThread().getName()+id+"哈哈哈";
    }
    @HystrixCommand(fallbackMethod = "getExnption",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "2000")
    })
    public String getHystrixSleep(Integer id){
        int time=3/0;
        try {
            TimeUnit.SECONDS.sleep(time);
        }catch (InterruptedException e) {
            e.printStackTrace();
        }
        return Thread.currentThread().getName() + ","+id + "耗时多少："+time;
    }
    public String getExnption(Integer id){
        return "超时请求，等待或者重试";
    }
}
